﻿Imports NUnit.Framework
Imports System.Data.SqlClient
Imports KumaSystem.Activities.Web
Imports Microsoft.Activities.UnitTesting

<TestFixture()>
Public Class TestWebMethod

    <TestCase("http://www.google.co.jp")>
    <TestCase("http://wfdesignerexpress.codeplex.com/")>
    <TestCase("http://blogahf.blogspot.com/")>
    Public Sub TestGetWeb(ByVal address As String)

        Dim testActivity As New WebGetActivity With {.Address = address}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        wfInvoker.AssertOutArgument.IsNotNull("StatusCode")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseHeader")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseBody")

        Console.WriteLine("")
        Console.WriteLine("Result : " + wfInvoker.OutArguments("StatusCode").ToString)
        Console.WriteLine("Header : " + wfInvoker.OutArguments("ResponseHeader").ToString)
        Console.WriteLine("Body : " + wfInvoker.OutArguments("ResponseBody").ToString)

    End Sub

    <Test()>
    Public Sub TestGetUserAgentStrings()
        Dim testActivity As New GetUserAgentStringsActivity
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        wfInvoker.AssertOutArgument.IsNotNull("Result")
        Console.WriteLine("User Agent : " + wfInvoker.OutArguments("Result").ToString)

    End Sub

    <Category("Use wcf service")>
    <TestCase("http://localhost:50660/Service1.svc/api")>
    Public Sub TestGetWebLocal(ByVal address As String)

        Dim testActivity As New WebGetActivity With {.Address = address}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        wfInvoker.AssertOutArgument.IsNotNull("StatusCode")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseHeader")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseBody")

        Console.WriteLine("")
        Console.WriteLine("Result : " + wfInvoker.OutArguments("StatusCode").ToString)
        Console.WriteLine("Header : " + wfInvoker.OutArguments("ResponseHeader").ToString)
        Console.WriteLine("Body : " + wfInvoker.OutArguments("ResponseBody").ToString)

    End Sub

    <Category("Use wcf service")>
    <TestCase("http://localhost:50660/Service1.svc/api")>
    Public Sub TestDeleteWebLocal(ByVal address As String)

        Dim deleteData = "TEST DELETE DATA"
        Dim testActivity As New WebDeleteActivity With {
            .Address = address, .ContentType = "application/x-www-form-urlencoded",
            .RequestBody = deleteData}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        wfInvoker.AssertOutArgument.IsNotNull("StatusCode")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseHeader")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseBody")

        Console.WriteLine("")
        Console.WriteLine("Result : " + wfInvoker.OutArguments("StatusCode").ToString)
        Console.WriteLine("Header : " + wfInvoker.OutArguments("ResponseHeader").ToString)
        Console.WriteLine("Body : " + wfInvoker.OutArguments("ResponseBody").ToString)

    End Sub

    <Category("Use wcf service")>
    <TestCase("http://localhost:50660/Service1.svc/api")>
    Public Sub TestPostWebLocal(ByVal address As String)

        Dim postData = "TEST POST DATA"
        Dim testActivity As New WebPostActivity With {
            .Address = address, .ContentType = "application/x-www-form-urlencoded",
            .RequestBody = postData}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        wfInvoker.AssertOutArgument.IsNotNull("StatusCode")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseHeader")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseBody")

        Console.WriteLine("")
        Console.WriteLine("Result : " + wfInvoker.OutArguments("StatusCode").ToString)
        Console.WriteLine("Header : " + wfInvoker.OutArguments("ResponseHeader").ToString)
        Console.WriteLine("Body : " + wfInvoker.OutArguments("ResponseBody").ToString)

    End Sub

    <Category("Use wcf service")>
    <TestCase("http://localhost:50660/Service1.svc/api")>
    Public Sub TestPutWebLocal(ByVal address As String)

        Dim putData = "TEST PUT DATA"
        Dim testActivity As New WebPutActivity With {
            .Address = address, .ContentType = "application/x-www-form-urlencoded",
            .RequestBody = putData}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        wfInvoker.AssertOutArgument.IsNotNull("StatusCode")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseHeader")
        wfInvoker.AssertOutArgument.IsNotNull("ResponseBody")

        Console.WriteLine("")
        Console.WriteLine("Result : " + wfInvoker.OutArguments("StatusCode").ToString)
        Console.WriteLine("Header : " + wfInvoker.OutArguments("ResponseHeader").ToString)
        Console.WriteLine("Body : " + wfInvoker.OutArguments("ResponseBody").ToString)

    End Sub

End Class
